﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GanagroLiteBO;

namespace GanagroLite
{
    public partial class FormTatuaje : GanagroLite.WinPart
    {

        public FormTatuaje()
        {
            InitializeComponent();
            this.bindingSourceMain.DataSource = new Tatuajes();
        }

        #region Internal methods

        protected internal override object GetIdValue()
        {
            return "Comprar Semovientes";
        }

        public override string ToString()
        {
            return "Comprar Semovientes";
        }

        #endregion

        #region Bindingsource Events

        #endregion

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            Cursor cCursor = System.Windows.Forms.Cursor.Current;
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            try
            {
                bindingSourceMain.SuspendBinding();

                string errorMessages = string.Empty, infoMessages = string.Empty;
                string ultimoCodigo = string.Empty;

                utilities.Guardar_View<GLiteBO>((BindingListView<GLiteBO>)bindingSourceMain.DataSource, ref infoMessages, ref errorMessages, ref ultimoCodigo,true);

                if (errorMessages.Length > 0)
                {
                    MessageBox.Show(errorMessages, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                MessageBox.Show(infoMessages, "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);

                bindingSourceMain.ResumeBinding();

                ((BindingListView<GLiteBO>)bindingSourceMain.DataSource).Clear();

                MainForm.Instance.StatusLabel2.Text = string.Format("Ultimo Codigo procesado: {0}", ultimoCodigo);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = cCursor;
            }

        }

        private void buttonSalir_Click(object sender, EventArgs e)
        {
            MainForm.Instance.StatusLabel1.Text = string.Empty;
            this.bindingSourceMain.CancelEdit();
            this.Close();
        }
    }
}
